#include "view_time_2.h"
#include "view_time_3.h"
#include "view_time_2_3.inc"
#include "display_ctrl.h"
#include "platform_assert.h"
#include "lfs_file_manager_auto.h"
#include "rtc.h"
#include "datetime.h"
#include "blecom.h"
#include "battery_ctrl.h"
#include "sport_his.h"
#include "display_ctrl.h"
#include "display_interface.h"
#include "datetime.h"
#include "heart_rate_interface.h"
#include "font_mngr.h"
//#include "view_common.h"
#include "app_trace.h"
typedef struct
{
    uint16_t start_color;
    uint16_t end_color;
    const uint8_t *zip_image;
} home_style_info_t;

static const home_style_info_t home_styles[2] = {
    // 红
    {0xf98c, 0xf943, (uint8_t *)zip_image_ring_circle},
    // 橙色
    {0xf4c3, 0xfa42, (uint8_t *)zip_image_ring_circle},
};
static void view_time_2_3_display(int color_index)
{
    bool is_ble_connected = false;
    int hour = 0;
    int minute = 0;
    int month = 0;
    int day = 0;
    int week_index = 0;
    int steps = 0;
    bool is_charge = false;
    int battery_percent = 0;
    int show_index = 0;
    int battery_level = 0;
    int pm_type = 0;

    is_ble_connected = disp_ctrl.com_data.u_temp[1];
    hour = disp_ctrl.com_data.u_temp[6];
    minute = disp_ctrl.com_data.u_temp[7];
    month = disp_ctrl.com_data.u_temp[4];
    day = disp_ctrl.com_data.u_temp[5];
    week_index = disp_ctrl.com_data.u_temp[9] - 1;
    steps = disp_ctrl.com_data.u_temp[10];
    is_charge = disp_ctrl.com_data.u_temp[2];
    battery_percent = disp_ctrl.com_data.u_temp[3];
    show_index = disp_ctrl.auto_refresh_count;
    battery_level = battery_ctrl_get_level(battery_percent);
    pm_type = disp_ctrl.com_data.u_temp[8];
#if 0
#warning debug
    is_ble_connected = true;
    // is_charge = true;
    pm_type = 2;
    steps = 12345;
#endif
    if (is_ble_connected)
    {
        draw_on_chip_unzip_image(0, 0, g_home_ble_icon);
    }

    draw_on_chip_unzip_image(65, 0, g_batt_box);
    if (is_charge)
    {
        draw_on_chip_unzip_image_with_forecolor(67, 2, home_batt[show_index % 5], home_styles[color_index].start_color);
    }
    else
    {
        draw_on_chip_unzip_image_with_forecolor(67, 2, home_batt[battery_level], home_styles[color_index].start_color);
    }

    if (pm_type)
    {
        draw_on_chip_unzip_image(58, 64, g_am_pm[pm_type - 1]);
    }
    draw_on_chip_gradients_image(25, 6, zip_image_home_num_14x32[hour / 10], home_styles[color_index].start_color, home_styles[color_index].end_color);
    draw_on_chip_gradients_image(41, 6, zip_image_home_num_14x32[hour % 10], home_styles[color_index].start_color, home_styles[color_index].end_color);
    draw_on_chip_image(25, 42, zip_image_home_num_14x32[minute / 10]);
    draw_on_chip_image(41, 42, zip_image_home_num_14x32[minute % 10]);

    draw_on_chip_gradients_image(8, 80, home_styles[color_index].zip_image, home_styles[color_index].start_color, home_styles[color_index].end_color);
    draw_on_chip_image_num_center(steps, 0, 105, 79, 17, zip_small_num_7x17, 7, 1, draw_type_filter_color);

    draw_on_chip_image(0, 149, zip_date_num_5x10[month / 10]);
    draw_on_chip_image(6, 149, zip_date_num_5x10[month % 10]);
    draw_on_chip_image(17, 149, zip_date_num_5x10[day / 10]);
    draw_on_chip_image(23, 149, zip_date_num_5x10[day % 10]);
    draw_on_chip_image(12, 149, zip_date_num_slash);

    draw_on_chip_image(51, 149, zip_weekday[week_index]);
}
void view_time_2_display(void)
{
    view_time_2_3_display(0);
}
void view_time_3_display(void)
{
    view_time_2_3_display(1);
}
